<?php /*a:1:{s:65:"/www/wwwroot/www.moxiongdi.com/app/admin/view/database/index.html";i:1698050634;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title><?php echo htmlentities($pagetitle); ?></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/admin/style/admin.css" media="all">
  <link rel="stylesheet" href="/static/admin/style/global.css" media="all">  
  <style>
	  .cache-progress{ width: 100%; height: 100%; background:rgba(0,0,0,.7); position: fixed; z-index: 1024;left:0px; top: 0px;}
	  .cache-progress .layui-progress{position: fixed; top: 30%; width:80%; margin-left: 10%; z-index: 1024;}
  </style>  
</head>
<body>

	<div class="layui-fluid">
	<div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <div>
                <div class="header-left" style="width:80%">
					  <div class="layui-inline">
						  <a class="layui-btn layuiadmin-btn-list" onclick="set_optimize()">优化表</a>
					  </div>      
					  <div class="layui-inline">
						  <a class="layui-btn layuiadmin-btn-list" onclick="set_repair()">修复表</a>
					  </div>   
					  <div class="layui-inline">
						  <a class="layui-btn layuiadmin-btn-list" onclick="set_bake()">立即备份</a>
					  </div>  
                </div>
                <div class="header-right search-field" style="width:18%;">

					  <div class="layui-inline">
						  <a class="layui-btn layuiadmin-btn-list" href="<?php echo url('recovery'); ?>">备份列表</a>
					  </div> 

                </div>
                <div class="clear"></div>
            </div>


        </div>


	<div class="layui-card-body">
	<form class="layui-form" action="" onsubmit="return save_form(this,success_fun)" lay-filter="component-form-element">
	<table class="layui-table">
	  <colgroup>
		<col width="150">
		<col width="150">
		<col width="200">
		<col>
	  </colgroup>
	  <thead>
		<tr>
			<th width="5%"> <input type="checkbox"  value="0" class="checkall" lay-ignore/></th>
			<th width="40%" style="text-align:left;">表名</th>
			<th width="10%" style="text-align:left;">数据量</th>
			<th width="10%" style="text-align:left;">数据大小</th>
			<th width="10%">类型</th>
			<th width="10%">编码</th>
			<th width="20%">备注</th>
		</tr> 
	  </thead>
	  <tbody>
	  <?php foreach($data as $key=>$v): ?>
		<tr>
		  <td style="text-align: center;"><input type="checkbox"  name="tables[]" class="chekboxs" lay-ignore value="<?php echo htmlentities($v['name']); ?>"/></td>
		  <td class="tab-title"><a href="<?php echo url('show_field',array('table'=>$v[name])); ?>" class="iframe" data-width="70%" data-height="90%" target="_blank"><?php echo htmlentities($v['name']); ?></a></td>
		  <td><?php echo htmlentities($v['rows']); ?></td>
		  <td><?php echo htmlentities(format_bytes($v['data_length'])); ?></td>
		  <td class="center"><?php echo htmlentities($v['engine']); ?></td>
		  <td class="center"><?php echo htmlentities($v['collation']); ?></td>
		  <td class="center"><?php echo !empty($v[comment]) ? htmlentities($v[comment]) : "-"; ?></td>
		</tr>
	   <?php endforeach; ?>
	  </tbody>
	</table>  
	</form>				  
	</div>
      
	</div>
</div>

  <script src="/static/admin/layui/layui.js"></script>
  <script src="/static/js/jquery.min.js"></script>    
  <script src="/static/js/globals.js"></script>  
  <script>
	var element;
  layui.config({
    base: '/static/admin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,admin = layui.admin;
    element = layui.element;//注意这里的的element不要var，这是全局变量
  });
//优化表
function set_optimize(){
    $("form").attr("action","<?php echo url('optimize'); ?>");
    save_form($("form"),function(){
        layer.msg("优化表成功！");
    });
}
//修复表
function set_repair(){
    $("form").attr("action","<?php echo url('repair'); ?>");
    save_form($("form"),function(){
        layer.msg("修复表成功！");
    });
}

//备份表
function set_bake(){
    if(confirm("在数据备份的时候不能刷新或者关闭浏览器，否则备份的数据不完整")==true){
        $("form").attr("action","<?php echo url('Start_DoBak'); ?>");
        save_form($("form"),function(data){
            //开始备份
            $("form").attr("action","<?php echo url('Ebak_BakExe'); ?>");
            //进度条初始化
			$("body").append('<div class="cache-progress"><div class="layui-progress layui-progress-big"  lay-showpercent="true" lay-filter="component-progress-demo" style=""><div class="layui-progress-bar layui-bg-green" lay-percent="1%"></div></div></div>');
            window.onbeforeunload = function(){ return "正在备份数据库，请不要关闭！" }
			//这里一定要做个延迟，因为append后无法立即渲染
			setTimeout(function(){
				element.render('progress');
				//初始化成功，下面开始备份数据
				var param={
					"start":0,
					"p":0,
					"t":0,
				};
				backup(param);
			},200);
        });
    }

}
//
function backup(param){
    $.get("<?php echo url('Ebak_BakExe'); ?>", param, function(result){
        if(result.code){
            var data=result.msg;			
            //备份进度
			element.progress('component-progress-demo', data.progress+"%");	
            //
            if(data.bake_end==1){
                layer.msg("备份完成,正在前往查看的路上...",function(){
                    location.href="<?php echo url('recovery'); ?>";
                });
                window.onbeforeunload = function(){ return null }
                return;
            }else{
                backup(data);
            }
        }else{
			alert("备份出错");
		}
    }, "json");
}
  </script>

</body>
</html>
